﻿#region 命名空间

using System;
using System.Web.UI.WebControls;
using WinnerCMS.BLL;
using WinnerCMS.Model;

#endregion

namespace WinnerCMS.WebUI.Admin.Member
{
    public partial class Message : WebFactory.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind(1);
            }
        }

        private string Action
        {
            get
            {
                var obj = ViewState["Action"];
                if (obj == null)
                {
                    return null;
                }
                return obj.ToString();
            }
            set { ViewState["Action"] = value; }
        }

        private void Bind(int PageNo)
        {
            this.GV_List.EmptyDataTemplate = GetTemplate(this);
            var pp = new PagingParam();
            pp.PageSize = this.PageNavigation1.PageSize;
            pp.PageNo = PageNo;


            if (Action == "Search")
            {
                this.L_Path.Text = "<a href=\"Member.aspx\">会员中心</a> → <a href=\"Message.aspx\">短消息管理</a> → 短信搜索";
            }
            else
            {
                this.L_Path.Text = "<a href=\"Member.aspx\">会员中心</a> → <a href=\"Message.aspx\">短消息管理</a>";
            }

            this.GV_List.DataSource = new MessageManage().BindList(this.ddlSort.SelectedValue,
                this.txtKeyWord.Text.Trim(), pp);
            this.GV_List.DataBind();
            this.PageNavigation1.RecordCount = pp.RecordCount;
        }

        protected void GV_List_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                var myTableCell = e.Row.Cells[7]; //删除
                var btnDel = (LinkButton) myTableCell.Controls[0];
                btnDel.Attributes.Add("onclick", "return confirm('您确定要删除？');");
            }
        }

        protected void GV_List_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            var index = Convert.ToInt32(e.CommandArgument);
            var ID = this.GV_List.DataKeys[index].Value.ToString();
            if (e.CommandName == "Delete")
            {
                new MessageManage().Delete(ID, this.UpdatePanel1);
                Bind(1);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            Action = "Search";
            Bind(1);
        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            new MessageManage().BatchToDo(this.GV_List, this.ddlBatchToDo, this.UpdatePanel1);
            Bind(this.PageNavigation1.PageNo);
        }

        protected void GV_List_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
        }

        protected void PageNavigation1_PageChanging(object src, WebControls.PageChangingEventArgs e)
        {
            Bind(e.NewPageIndex);
        }
    }
}